package chamber.two.guice;

import chamber.two.christmastown.Reindeer;
import chamber.two.christmastown.ReindeerImpl;
import chamber.two.factory.ReindeerFactory;
import chamber.two.function.ToReindeerFunction;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.Service;
import com.google.common.util.concurrent.ServiceManager;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.assistedinject.FactoryModuleBuilder;

/**
 * Created by Gerardo on 1/3/14.
 */
public class ChamberTwoModule extends AbstractModule {
    @Override
    protected void configure() {
        install(new FactoryModuleBuilder().implement(Reindeer.class, ReindeerImpl.class).build(ReindeerFactory.class));
        bind(ToReindeerFunction.class);
        try {
            bind(ServiceManager.class).toConstructor(ServiceManager.class.getConstructor(Iterable.class));
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
    }

    @Provides
    Iterable<? extends Service> provideServices(final ToReindeerFunction toReindeer) {
        Iterable<String> names = Lists.newArrayList("Dasher", "Dancer", "Prancer", "Vixen", "Comet", "Cupid", "Donder", "Blitzen", "Rudolph");
        return Iterables.transform(names, toReindeer);
    }
}
